﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using IMPlant.Core.Data.Unity;
using System.Data;
using SMTC.Model.Model;

namespace SMTC.Dao.AnalyzePara
{
    public class AnalyzeParaProcessServicesDao : BaseDao
    {
        #region 参数设置SQL
        private const string SQL_INSERT_Para = @"INSERT INTO dbo.SMT_para (
	                                                TargetTime,
	                                                EquipmentProcurementCycle,
	                                                WarningLeadTime,
	                                                YellowAlert,
	                                                RedAlert
                                                ) VALUES ( 
	                                                /* TargetTime - float */ @TargetTime,
	                                                /* EquipmentProcurementCycle - int */ @EquipmentProcurementCycle,
	                                                /* WarningLeadTime - int */ @WarningLeadTime,
	                                                /* YellowAlert - int */ @YellowAlert,
	                                                /* RedAlert - int */ @RedAlert ) ";

        private const string SQL_UPDATE_Para = @"UPDATE dbo.SMT_para SET 
                                                TargetTime = @TargetTime,
                                                EquipmentProcurementCycle = @EquipmentProcurementCycle,
                                                WarningLeadTime = @WarningLeadTime,
                                                YellowAlert = @YellowAlert,
                                                RedAlert = @RedAlert";
        #endregion
        #region 处理方法
        public bool InsertInto(SMT_paraModel model)
        {
            DbParameter[] parameter = 
            {
                 DBparameterBuild.Build("@EquipmentProcurementCycle",model.EquipmentProcurementCycle)
                ,DBparameterBuild.Build("@WarningLeadTime",model.WarningLeadTime)
                ,DBparameterBuild.Build("@TargetTime",model.TargetTime)
                ,DBparameterBuild.Build("@YellowAlert",model.YellowAlert)
                ,DBparameterBuild.Build("@RedAlert",model.RedAlert)
               
            };

            try
            {
                return DBTemplete.ExcuteNoQuery(CommandType.Text, SQL_INSERT_Para, parameter) > 0;
            }
            catch
            {
                return false;
            }
        }
        public bool UpdatePara(SMT_paraModel model)
        {
            DbParameter[] parameter = 
            {
                 DBparameterBuild.Build("@EquipmentProcurementCycle",model.EquipmentProcurementCycle)
                ,DBparameterBuild.Build("@WarningLeadTime",model.WarningLeadTime)
                ,DBparameterBuild.Build("@TargetTime",model.TargetTime)
                ,DBparameterBuild.Build("@YellowAlert",model.YellowAlert)
                ,DBparameterBuild.Build("@RedAlert",model.RedAlert)               
            };

            try
            {
                return DBTemplete.ExcuteNoQuery(CommandType.Text, SQL_UPDATE_Para, parameter) > 0;
            }
            catch
            {
                return false;
            }
        }
        #endregion
    }
}
